<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-员工管理">
</@frame.head>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 后台管理中心 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 员工管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
<form method="post" name="query_employee_form"  id="query_employee_form" action="${contextPath}/employee/employee_list" >    
   <input type="hidden" name="page" value="${pagination.pageNo}"  id="page" />                        
    <div class="text-c">
        <table class="table">
           <tr>  
           <td>员工姓名：</td>
           <td><input type="text" class="input-text  radius"  placeholder="员工名" id="" name="name" value="${employeeQo.name}"></td>     
           <td>创建时间：</td>
           <td><input  type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'createDateEnd\')||\'%y-%M-%d\'}',readOnly: true })" id="createDateStart" 
               value='${(employeeQo.createDateStart?string("yyyy-MM-dd"))!}' name="createDateStart"  class="input-text Wdate" style="width:120px;">
                                                至
               <input  type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\'createDateStart\')}',maxDate:'%y-%M-%d',readOnly: true })" id="createDateEnd" 
               value='${(employeeQo.createDateEnd?string("yyyy-MM-dd"))!}' name="createDateEnd"    class="input-text Wdate" style="width:120px;">
           </td>
          </tr>
          <tr>
               <td>机构名：</td>
           	   <td>
           
	           <span class="select-box radius">
	           <select class="select"  name="organizationId" id="organizationId">
	           <option value>请选择机构</option>
	             <#list organizationList as list>  
	                 <option value="${list.id?c}" <#if list.id==employeeQo.organizationId>selected="selected"</#if>>${list.name}</option>
	             </#list>
	           </select>
	           </span>
	           </td> 
	           <td>部门名：</td>
           	   <td>
           
	           <span class="select-box radius">
	           <select class="select"  name="departmentId" id="departmentId" disabled="disabled">
	           <option value="-1">请先选择机构</option> 
	           </select>
	           </span>
	           </td> 
          </tr>
         <tr> 
         <td colspan="6" style="text-align:center;" >
           <input class="btn btn-success radius" type="button"  onclick="search();"  value="搜索" />
           <input class="btn btn-success radius" type="button"  onclick="toIsEmpty();" value="重置" />
         </td>
         </tr>
      </table>
    </div>
</form>

    <div class="cl pd-5 bg-1 bk-gray mt-20"> 
    <span class="l">
     <a href="javascript:;" onclick="add()" class="btn btn-primary radius"> 添加新员工</a> 
    </span>
    <span class="r">共有数据：<strong>${pagination.totalCount}</strong> 条</span> </div>
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr  class="text-c">
            <th >员工编号</th>
            <th >员工姓名</th>
            <th >入职日期</th>
            <th >性别</th>
            <th >年龄</th>
            <th >状态</th>
            <th >机构名</th>
            <th >部门名</th>
            <th >创建时间</th>
            <th >备注</th>
            <th >操作</th>
        </tr>
        </thead>
        <tbody>
       <#if pagination.list?? && (pagination.list?size &gt; 0) >
        <#list pagination.list as employee> 
             <tr  class="text-c">
                <td>${employee.id?c}</td>
                <td>${employee.name}</td>
                <td>${(employee.empDate?string("yyyy-MM-dd"))!}</td>
                <td width="55">                                        
                     <#if employee.sex=1><span class="label label-success radius">男</span>
                     <#elseif employee.sex=2><span class="label label-success radius">女</span>
                     </#if> 
                </td>
                <td>${employee.age}</td>
                <td width="55">                                        
                     <#if employee.state=1><span class="label label-success radius">在职</span>
                     <#elseif employee.state=2><span  class="label radius">离职</span>
                     </#if> 
                 </td>
                <td>${employee.organization.name}</td>
                <td>${employee.department.name}</td>
                <td>${(employee.createDate?string("yyyy-MM-dd"))!}</td>
                <td>${employee.remark}</td>
                <td>					
               	<a href="javaScript:void(0);" onclick="edit(${employee.id?c})">修改</a>							
              	<a href="javaScript:void(0);" onclick="del(${employee.id?c})">删除</a>							
               </td>
        </tr>
      </#list></#if>
     </tbody>
    </table>
    <div id="div_page" style="padding-top: 10px;float: right"></div>
</div>
<@frame.end "default">
</@frame.end>
</html>
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/laypage/laypage.js"></script>
<script type="text/javascript" src="${contextPath}/resources/js/brand/query_brand.js"></script>
<script type="text/javascript">
var path="${contextPath}";
laypage({
    cont: 'div_page',//容器。值支持id名、原生dom对象，jquery对象。
    pages: ${pagination.totalPage},//通过后台拿到的总页数
    curr:  ${pagination.pageNo} || 1, //当前页
	skip: true, //是否开启跳页
	first: 1, //将首页显示为数字1,。若不显示，设置false即可
	last: ${pagination.totalPage}, //将尾页显示为总页数。若不显示，设置false即可
    jump: function(obj , first){//触发分页后的回调
        if(!first){ //点击跳页触发函数;当前页为obj.curr
            $("#page").val(obj.curr);
            $("#query_employee_form").submit();
        }
    }
})  
$(document).ready(function(){
         //顶级分类方法
       $("#organizationId").change(function(){
    	   
		           $("#departmentId").removeAttr("disabled");
		           		var id = $('#organizationId').val();
		           		if(id == 0){
			           		$("#departmentId").attr("disabled", "disabled");
			           	  	$("#departmentId").empty();
			           	 	$("#departmentId").prepend("<option value='-1'>请先选择部门</option>");
			           	 	return false;
		           		}
		           		  var url=path+"/employee/query_department_list?id="+id;
				           $.post(url,'',function(msg){
					           if(msg!="notfound")
					           {  
							     $("#departmentId").html(msg);    
					           }
				          });
		            });
});
function search(){
    $("#page").val("1");
    $("#query_employee_form").submit();
}	
function add(){
	layer_show('添加员工',path+'/employee/employee_toadd','800','700');
}
function edit(id){
	layer_show('修改员工信息',path+'/employee/employee_toedit?id='+id,'800','700');
}
function del(id){
	layer.confirm("确定删除此员工吗?",function(){
		  $.ajax({
				url : path+"/employee/employee_delete",
				cache : false,
				type : 'post',
				dataType : 'html',
				data : {
					"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
	        		if(message == "200"){
	                    layer.msg('操作成功!',{icon:1,time:1000},function(){
	                        window.location.reload();
	                    });
	 				}else if(message == "500"){
	 					layer.alert("系统繁忙！");
	 				}else{
	 					layer.alert(message);
	 				}
				}
		  });
	});
}
function toIsEmpty(){
	document.getElementsByName("name")[0].value= "";
	$("#createDateStart").val("");
	$("#createDateEnd").val("");
	$("#organizationId").val("");
	$("#departmentId option").remove();  
	$("#departmentId").append("<option value=\"-1\">请先选择机构</option>");  
	$("#departmentId").val("-1");  
}
</script>